package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.UseableCount
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.ITurnVipView
import de.baumann.browser.model.LicenceModel
import de.baumann.browser.utils.updateLicenceStatus

class TurnVipPresenter : BasePresenter<ITurnVipView>() {

    private val licenceModel = LicenceModel()
    fun getLicenceCount() {
        this.licenceModel.licenceCount
                .subscribe(object : OdinObserver<UseableCount>(view) {
                    override fun onSuccess(data: UseableCount?) {
                        if (view != null && data != null) {
                            view.setUseableCount(data.useableCount)
                            view.setUseableLicence(data.useableLisence)
                        }
                    }
                })
    }


    fun licenceActive(licenceId: String) {
        licenceModel.licenceActive(licenceId)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        updateLicenceStatus(3)
                        if (view != null)
                            view.turnVipSuccess()
                    }
                })
    }
}